package com.example.guet_assistant.service.impl;

import cn.hutool.json.JSONObject;
import com.example.guet_assistant.result.Result;
import com.example.guet_assistant.service.ChatService;
import com.example.guet_assistant.service.tp.AssistantService;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.annotation.Resource;
import lombok.SneakyThrows;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ChatServiceImpl implements ChatService {
    @Resource
    private AssistantService assistantService;
    private final ObjectMapper mapper = new ObjectMapper();

    @SneakyThrows
    @Override
    public Result<Map<String, String>> qa(String content) {
        List<Map<String, String>> messages = new ArrayList<>();
        Map<String,String> message = new HashMap<>();
        message.put("type","user");
        message.put("content",content);
        messages.add(message);
        JSONObject json = assistantService.qa("json", messages);
        return Result.success(mapper.readValue(json.toString(), new TypeReference<>() {}));
    }
}
